package com.itshops.service.impl;

import com.itshops.dao.AddressDao;
import com.itshops.dao.impl.AddressDaoImpl;
import com.itshops.entity.Address;
import com.itshops.service.AddressService;

import java.sql.SQLException;
import java.util.List;

public class AddressServiceImpl implements AddressService {
   AddressDao addressDao= new AddressDaoImpl();
    @Override
    public List<Address> findAll(int uid) throws SQLException {

        List<Address> address=addressDao.selectAddressByUid(uid);

        return address;
    }

    @Override
    public void addAddress(Address address) throws SQLException {
        addressDao.insertAddress(address);
    }

    @Override
    public void deleteAddress(String aid) throws SQLException {
        addressDao.deleteAddress(aid);
    }

    @Override
    public void setAddressDefault(String aid, int uid) throws SQLException {
        //将对应id的地址改为默认，其他改为非默认
        addressDao.updateAddressDefault(aid);
        addressDao.updateAddressNoDDefault(aid,uid);
    }

    @Override
    public void updateAddress(Address address) throws SQLException {
        addressDao.updateAddress(address);
    }
}
